package com.youyou.sso.service.impl;

import com.youyou.sso.bean.UserInfo;
import com.youyou.sso.service.ISsoService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

/**
 * //TODO 添加类/接口功能描述
 *
 * @author 刘朋
 * <br/>date 2021-09-06
 */
@Service
public class SsoServiceImpl implements ISsoService {

    private static Map<String , Object> cacheMap = new HashMap<>();

    @Override
    public String login(String userName, String password) {
        //todo 查询用户信息逻辑。。。自己实现


        UserInfo userInfo = new UserInfo();
        userInfo.setUsername(userName);
        userInfo.setPassword(password);

        String token = UUID.randomUUID().toString();
        cacheMap.put(token ,userInfo);

        return token;
    }

    @Override
    public UserInfo getUserInfo(String token) {
        Object o = cacheMap.get(token);
        if(o instanceof UserInfo){
            return (UserInfo) o;
        }
        return null;
    }

    @Override
    public boolean login(String token) {
        Object o = cacheMap.get(token);
        return Objects.nonNull(o);
    }
}
